/**
 * @author Francesco di Dio
 * Date: 20/apr/2013
 * Titolo: AbstractJKModel.java
 * Versione: 
 */

/**
 * Copyright (c) 2013 Francesco di Dio.
 * tabuto83@gmail.com 
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */
package com.tabuto.jkeys.models;

import java.io.Serializable;

/**
 * 
 * @author user
 * 
 */
public class AbstractJKeyModel implements Serializable,
		Comparable<AbstractJKeyModel> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4905152299200848539L;

	private int id = 0;
	private String name = "";

	public AbstractJKeyModel() {
	}

	public AbstractJKeyModel(String name) {
		setName(name);
	}

	public AbstractJKeyModel(int id, String name) {
		setId(id);
		setName(name);
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = (id > 0 ? id : 0);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = (name != null ? name : "");
	}

	@Override
	public int hashCode() {
		int result = 17;
		result = 31 * result + getId();
		result = 31 * result + getName().hashCode();
		return result;
	}

	@Override
	public boolean equals(Object o) {
		if (o == null)
			return false;
		if (!(o instanceof AbstractJKeyModel))
			return false;

		AbstractJKeyModel toEvalue = (AbstractJKeyModel) o;

		return (this.getName().equals(toEvalue.getName()) && this.getId() == (toEvalue
				.getId()));

	}

	@Override
	public int compareTo(AbstractJKeyModel o) {
		if (o == null)
			throw new NullPointerException("Try to compare a null object");
		return this.getName().compareTo(o.getName());
	}

}
